<?php

namespace App\Http\Controllers\Api\qyf;
use App\Common\Responses;
use PHPExcel;
use PHPExcel_IOFactory;

use App\Http\Controllers\Controller;

class Excel extends Controller
{
    // 数据转Excel
    function excel(){
       $excel= new PHPExcel();
        // 读取 Excel 文件
        $objPHPExcel = PHPExcel_IOFactory::load('path/to/file.xls');
        // 设置 Excel 文件的属性
        $objPHPExcel->getProperties()->setCreator("notYetCat")
            ->setLastModifiedBy("notYetCat")
            ->setTitle("备份")
            ->setSubject("Excel")
            ->setDescription("数据库数据")
            ->setKeywords("Excel")
            ->setCategory("Category");

        try {
            //设置当前工作表
            $objPHPExcel->setActiveSheetIndex(0);

            $objPHPExcel->getActiveSheet()->setCellValue('A1',);
            //保存文件到指定目录
            $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
            $objWriter->save('path/to/file.xls');
        } catch (\PHPExcel_Exception $e) {
            return Responses::error(['error'=>$e->getMessage()]);
        }

    }
}
